package com.kinglone.util;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class Paged<T>
  implements Serializable
{
  private static final long serialVersionUID = -3563058571948937207L;
  private int totalHit;
  private int pageNo;
  private int pageSize = 1;

  private List<T> listData = new ArrayList();

  public Paged()
  {
  }

  public Paged(List<T> listData, int totalHit, int pageNo, int pageSize) {
    this.listData = listData;
    this.totalHit = totalHit;
    this.pageNo = pageNo;
    this.pageSize = pageSize; }

  public Paged(List<T> listData, int totalHit, int pageNo, int pageSize, boolean needPaged) {
    int start = (pageNo - 1) * pageSize;
    if (start < 0) start = 0;
    int end = pageNo * pageSize;
    if ((listData != null) && (end > listData.size()))
      end = listData.size();
    this.listData = listData.subList(start, end);
    this.totalHit = totalHit;
    this.pageNo = pageNo;
    this.pageSize = pageSize; }

  public int getTotalHit() {
    return this.totalHit;
  }

  public void setTotalHit(int totalHit) {
    this.totalHit = totalHit;
  }

  public int getPageNo() {
    return this.pageNo;
  }

  public void setPageNo(int pageNo) {
    this.pageNo = pageNo;
  }

  public int getPageSize() {
    return this.pageSize;
  }

  public void setPageSize(int pageSize) {
    this.pageSize = pageSize;
  }

  public List<T> getListData() {
    return this.listData;
  }

  public void setListData(List<T> listData) {
    this.listData = listData;
  }

  public int totalPage()
  {
    int totalPage = this.totalHit / this.pageSize;
    if (this.totalHit % this.pageSize != 0) {
      totalPage += 1;
    }
    return totalPage;
  }
}